
package com.webbei.Backstage.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import com.opensymphony.xwork2.ActionSupport;
import com.webbei.Backstage.service.BackstateSer;
import com.webbei.pojo.Orders;
import com.webbei.pojo.Trade;

public class selectOrderBydateandIndusname extends ActionSupport{
	private Integer productId;
	  private String mark;
	  private String startTime;
	  private String endTime;
      private String indusname;
      private String orderId;
      private String orderstate;
      private String sellername;
      private BackstateSer bao;
      private List<Orders> orderlist;
      private Orders order;
      private List<Trade> trades;
      private JSONArray jsonob;
      private String page;
  	  private int pagenow =1;
  	  private static final int maxpage = 50;
  	  private int pagecount;
  	  private int total;
 	public String execute(){
 		System.out.println("tradeId:"+orderId);
 		trades = new ArrayList<Trade>();
 		if(orderId!=null){
 		orderId = orderId.trim();
 		}
 		if(indusname!=null){
 		indusname = indusname.trim();
 		}
 		if(page!=null){
 	        	pagenow=Integer.parseInt(page);
 	        }
 	
 	       if("".equals(startTime)){
 	    	   startTime=null;
 	       }
 	       if("".equals(endTime)){
 	    	   endTime = null;
 	       }
 	      if("".equals(mark)){
 	    		mark=null;
 	    	}
 	     if("-1".equals(orderstate)){
 			orderstate=null;
 		}
 	       Map<String,Object> m = new HashMap<String, Object>();
 	       m.put("startTime", startTime);
 	       m.put("endTime", endTime);
 	       m.put("indusname", indusname);
 	       m.put("tradeId", orderId);
 	       m.put("desc", "desc");
 	      m.put("orstate", orderstate);
 	      System.out.println("----------------admin:"+m);
 	      if(mark!=null){
 				String[]marks = mark.split("，|,|[ \t]+");
 				mark = "";
 				for(int i=0;i<marks.length;i++){
 					String s = marks[i];
 					if(i==0){
 						mark += s;
 					}else{
 						mark+="|"+s;
 					}
 					
 				}
 			}
 	      m.put("mark", mark);
 	     
 	      m.put("sellername", sellername);
 	       total=bao.getOrdercount(m);
 	       
 			  pagecount = (total% maxpage) == 0 ? (total/maxpage): (total/maxpage+ 1);
 			  
 				if (pagenow> pagecount) {
 					pagenow=pagecount; 
 				}
 				if (pagenow< 1) {
 					pagenow = 1;
 				}
 				int start = (pagenow - 1) * maxpage;
 				m.put("start", start);
 				m.put("maxpage", maxpage);
 				System.out.println("selectOrderByDate....."+m);
 			orderlist = bao.getorderByday(m);
 				 int len=orderlist.size();
 				 for(int i=0;i<len;i++){
 					 Orders o = orderlist.get(i);
 					 if(orderlist.get(i).getIndustryId()!=null){
 					 order=new Orders();
 					 order.setIndustryName(bao.getindusNamebyid(orderlist.get(i).getIndustryId()));
 					 orderlist.add(order);
 					 }
 					 Trade t = new Trade();
 					 List<Orders> orders = bao.getOrdersByTradeId2(o.getTradeId());
 					 
 					 t.setOrders(orders);
 					 t.setCount(orders.size());
 					 t.setTradeId(o.getTradeId());
 					 trades.add(t);
 					 
 				 }
     	   return SUCCESS;
        }
 	public BackstateSer getBao() {
 		return bao;
 	}
 	public void setBao(BackstateSer bao) {
 		this.bao = bao;
 	}
 	
 
	public String getOrderId() {
		return orderId;
	}
	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}
	public List<Orders> getOrderlist() {
 		return orderlist;
 	}
 	public void setOrderlist(List<Orders> orderlist) {
 		this.orderlist = orderlist;
 	}
 	public String getPage() {
 		return page;
 	}
 	public void setPage(String page) {
 		this.page = page;
 	}
 	public int getPagenow() {
 		return pagenow;
 	}
 	public void setPagenow(int pagenow) {
 		this.pagenow = pagenow;
 	}
 	public int getPagecount() {
 		return pagecount;
 	}
 	public void setPagecount(int pagecount) {
 		this.pagecount = pagecount;
 	}
	public String getIndusname() {
		return indusname;
	}
	public void setIndusname(String indusname) {
		this.indusname = indusname;
	}
	public JSONArray getJsonob() {
		return jsonob;
	}
	public void setJsonob(JSONArray jsonob) {
		this.jsonob = jsonob;
	}
	public Orders getOrder() {
		return order;
	}
	public void setOrder(Orders order) {
		this.order = order;
	}
	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getEndTime() {
		return endTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	public String getMark() {
		return mark;
	}
	public void setMark(String mark) {
		this.mark = mark;
	}
	public List<Trade> getTrades() {
		return trades;
	}
	public void setTrades(List<Trade> trades) {
		this.trades = trades;
	}
	public Integer getProductId() {
		return productId;
	}
	public void setProductId(Integer productId) {
		this.productId = productId;
	}
	public String getSellername() {
		return sellername;
	}
	public void setSellername(String sellername) {
		this.sellername = sellername;
	}
	public String getOrderstate() {
		return orderstate;
	}
	public void setOrderstate(String orderstate) {
		this.orderstate = orderstate;
	}
}
